package com.qf.homeworkssm.controller;

import com.qf.homeworkssm.annotition.NullValidation;
import com.qf.homeworkssm.entity.User;
import com.qf.homeworkssm.service.UserService;
import com.qf.homeworkssm.utils.Contants;
import com.qf.homeworkssm.vo.HelloVo;
import com.qf.homeworkssm.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private UserService userService;

    @GetMapping("/test1")
    public ResultVo test1(@Validated  HelloVo helloVo){  //使用Validated  开启参数校验
        System.out.println(helloVo);

        return new ResultVo(Contants.SUCCESS_CODE,"ok");
    }


    @PostMapping("/test2")
    public ResultVo test2(@Validated  @RequestBody HelloVo helloVo){  //使用Validated  开启参数校验
        System.out.println(helloVo);

        return new ResultVo(Contants.SUCCESS_CODE,"ok");
    }

    @NullValidation
    @GetMapping("/test3")
    public ResultVo test3(@Validated  @NotNull String name,@Validated @NotNull Integer id){  //使用Validated  开启参数校验
        if (name == null){

        }
        System.out.println(name);
        System.out.println(id);


        return new ResultVo(Contants.SUCCESS_CODE,"ok");
    }


    @PostMapping("/get/{id}")
    public User getUser(@PathVariable("id") @RequestBody Integer id){
        return userService.getUser(id);
    }
}
